



//
//  UserCenterViewController.m
//  nncloud
//
//  Created by macfeel on 2019/5/14.
//  Copyright © 2019 macfai. All rights reserved.
//
#import "NLoginViewController.h"
#import "UserCenterViewController.h"
#import "UIColor+Hex.h"
#import "NBaseH5ViewController.h"
#import "AboutusViewController.h"
@interface UserCenterViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *nameArray;
@property (nonatomic,strong)NSArray *detailArray;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,assign)NSInteger currentPage;

@end

@implementation UserCenterViewController
#define cellIdentifier  @"filter"
//#define HeaderHight  290
#define PageSize 20

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        WeakStament(ws);
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - ScreenHeightFlex) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 55;
        //        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = kBackgroundColor;
//        [_tableView registerNib:[UINib nibWithNibName:@"FilterCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        //        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
        //        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            [ws loadData];
        //        }];
        //        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //            [ws loadMoreData];
        //        }];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = nil;
     [self.navigationItem setItemWithTitle:@"我的" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    self.nameArray = @[@"用户名",@"清除缓存",@"当前版本",@"关于我们",];
    self.detailArray = @[@"admin",@"2M",@"V1.0",@"",];
    [self.view addSubview:self.tableView];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = kSystemtBlue;
    btn.frame = CGRectMake(45, 60, ScreenWidth-90, 45);
    [btn setTitle:@"退出" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(tapOut) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius = 5.f;
    btn.layer.masksToBounds = YES;
    [btn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    
    
    UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth, 200)];
    bg.backgroundColor = kClearColor;
    
    [bg addSubview:btn];
    
    self.tableView.tableFooterView = bg;
    
    // Do any additional setup after loading the view from its nib.
}

////退出
-(void)tapOut{
    [self callLoginVC];
}



///调起登录页面
-(void)callLoginVC{
    
    NLoginViewController *login = [[NLoginViewController alloc]initWithNibName:@"NLoginViewController" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:login];
    //解决present延迟弹出
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:nav animated:YES completion:^{
            
        }];
    });
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //    return self.dataArray.count;
    return self.nameArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1
                                      reuseIdentifier: cellIdentifier];
    }
    
    //    NSDictionary *noteDictionary = [self.notes objectAtIndex: indexPath.row];
    //    cell.textLabel.text = noteDictionary[@"title"];
    //    cell.detailTextLabel.text = [self.dates objectAtIndex: indexPath.row];
    //    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.textLabel.textColor = kDarkGrayColor;
    cell.selectionStyle = 0;
    cell.textLabel.text = self.nameArray[indexPath.row];
    cell.accessoryType = 1;
    cell.detailTextLabel.text = self.detailArray[indexPath.row];
//    cell.detailTextLabel.text =
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ///
    WeakStament(ws);
    if (indexPath.row==0) {
        [AFToast showText:@"暂时不能修改"];
    }else if (indexPath.row==1){
        [SVProgressHUD show];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            ws.detailArray = @[@"admin",@"0M",@"V1.0",@"",];
            [ws.tableView reloadData];
             [AFToast showText:@"清除成功"];
            
        });
       
        
        
    }else if (indexPath.row==3){
        
//        [AFToast showText:@"开发中……"];
        AboutusViewController *about = [AboutusViewController new];
        [self.navigationController pushViewController:about animated:YES];
    }
    
}

@end
